import express from 'express'
import cors from "cors";
import path from "path";
import multer from "multer";
import login from "./api/login/login.js";
import classList from "./api/class/list.js";
import homeworkQuery from "./api/homework/list.js";
import homeworkDetail from "./api/homework/list_detail.js"
import finishedCount from "./api/homework/teacher/finishedCount.js"
import upload from "./api/upload/index.js";
import assign from "./api/homework/teacher/assign.js"
import doHomework from "./api/homework/student/assign.js"
import doHomeworkDetail from "./api/homework/submitted.js"
import homeworkReview from "./api/homework/teacher/review.js";
import getHomeworkReview from "./api/homework/reviewed.js"
import relatedAccount from "./api/login/relatedAccount.js";
import queryRelatedAccount from "./api/login/queryRelatedAccount.js";
import getUserinfo from "./api/login/getUserinfo.js";
import classDetail from "./api/class/list_detail.js";
import createClass from "./api/class/create.js";
import searchClass from "./api/class/search.js";
import checkUserInClass from "./api/class/checkUserInClass.js";
import joinClass from "./api/class/join.js";
import register from "./api/login/register.js";

let app = express();
let __dirname = path.resolve();
app.use(express.json());/*JSON 格式数据*/
app.use(express.static(__dirname));
app.use(multer({dest: './file/'}).any());
app.use(express.urlencoded({extended: true})); /*处理 URL 编码*/
app.use(cors()); /*跨域资源共享（CORS）中间件*/
app.use("/upload", upload)
app.use("/register", register)
app.use("/login", login)
app.use("/userInfo", getUserinfo)
app.use("/createClass", createClass)
app.use("/searchClass", searchClass)
app.use("/checkUserInClass", checkUserInClass)
app.use("/joinClass", joinClass)
app.use("/classList", classList)
app.use("/classInfo", classDetail)
app.use("/homeworkQuery", homeworkQuery)
app.use("/homeworkDetail", homeworkDetail)
app.use("/finishedCount", finishedCount)
app.use("/homeworkAssign", assign)
app.use("/doHomework", doHomework)
app.use("/doHomeworkDetail", doHomeworkDetail)
app.use("/homeworkReview", homeworkReview)
app.use("/getHomeworkReview", getHomeworkReview)
app.use("/relatedAccount", relatedAccount)
app.use("/queryRelatedAccount", queryRelatedAccount)

app.listen(8082, () => {
    console.log('服务已启动')
})